
ObjectRate = function( vars )	{

	Object.extend( obj = $$( '.ObjectRate' ).pop(), ObjectRate.proto );
	
	obj.stars	 	= obj.select( "a.rate" );
	obj.vars		= vars;
	obj.enabled		= true;
	
	return obj;
}



ObjectRate.proto =	{

	rate				: function() {
	
		this.stars.each( function( el, i ) {
			
			el.observe( 'mouseover', this.changeBackground.bind( this, el, i+1 ));
			el.observe( 'mouseout', this.deleteBackground.bind( this ));
			el.observe( 'click', this.submit.bind( this, el, i+1 ));
		}, this );
	},
	
	changeBackground	: function( el, i ) {
	
		if( this.enabled ) {
			for( var s = 1; s <= i; s = s+1 ) {
				this.select( '.s' + s ).pop().addClassName( 'active' );
			}
		}
	},
	
	deleteBackground	: function() {
		
		if( this.enabled ) {
			this.stars.each( function( el, i ) {
				el.removeClassName( 'active' );
			}, this );
		}
	},
	
	submit				: function( el, i ) {
	
		event.preventDefault();
		if( this.enabled ) {
			for( var s = 1; s <= i; s = s+1 ) {
				this.select( '.s' + s ).pop().addClassName( 'active' );
			}
			this.enabled = false;
	
			var value = i; 
			xhttp.send( '/xhttp.mod', {
				mod: "object.rate",
				action: "rate",
				vars: { vars: this.vars, value: value }
			}, this.pull_response.bind( this ) );
		}
	},
	
	pull_response		: function( response ) {
	
		this.insert( new Element( "span", { 'class': 'update' }).update( response.responseText ));
	}
}
